home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / appkit.687 < prev    next >
Text File  |  1992-02-06  |  2KB  |  64 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f3\fmodern Courier;\f1\fswiss Helvetica;}
  2. \paperw11440
  3. \paperh9000
  4. \margl120
  5. \margr120
  6. {\colortbl\red0\green0\blue0;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ul0\fs28 \
  8. Q:  I'm writing an application which can open either EPS or TIFF images using the NXImage class.  How can I determine what kind of file I've opened without hacking the file name?\
  9.  
  10. \i     \
  11.  
  12. \i0 A:  You can use the 
  13. \f3\fs24 isKindOf:
  14. \f0\fs28  method from the Object class:\
  15. \
  16.  
  17. \f3\fs24     id myNXImage, myImageRep;\
  18.     \
  19.     myNXImage = [[NXImage alloc] initFromFile: fileName];\
  20.     myImageRep = [myNXImage lastRepresentation];\
  21.     if ([myImageRep isKindOf: [NXBitmapImageRep class]])\
  22.     \{\
  23.         /* then I'm a TIFF file! */\
  24.     \}\
  25.     else if ([myImageRep isKindOf: [NXEPSImageRep class]])\
  26.     \{\
  27.         /* then I'm an EPS file! */\
  28.     \}\
  29.  
  30. \f0\fs28 \
  31. The key here is that the NXImage instance itself does not understand EPS or TIFF information per se.  NXImage manages the 
  32. \i representation
  33. \i0  classes [one NXImage may have multiple representations] which do understand EPS and TIFF information.\
  34. \
  35. Of course, it is reasonable to extract this information from the fileName as well.  The following code snippet can be used to do this:  [This approach will work under 1.0 as well as 2.0.]\
  36. \
  37.  
  38. \pard\tx620\tx1240\tx1860\tx2480\tx3100\tx3720\tx4340\tx4980\tx5600\tx6220\f3\fs24\fc0 #import <strings.h>\
  39. \
  40.     \
  41.     char *fileType = rindex(fileName, '.');\
  42. \
  43.     if (!fileType) \
  44.     \{\
  45.         /* then I'm not an appropriate file! */\
  46.     \} \
  47.     else if (!strcmp(fileType, ".tiff")) \
  48.     \{\
  49.         /* then I'm a TIFF file! */;\
  50.     \}\
  51.     else if (!strcmp(fileType, ".eps")) \
  52.     \{\
  53.         /* then I'm an EPS file! */\
  54.     \} \
  55.  
  56. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\fs28 \
  57. \
  58. QA687\
  59. \
  60. Not valid for 1.0, with exception noted.\
  61. Valid for 2.0                \
  62. \
  63.  
  64.